package com.vhall.component.controller.export;

import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.export.facade.ExportAdmFacade;
import com.vhall.component.entity.export.vo.AdmReExportReqVO;
import com.vhall.component.entity.export.vo.ExportAdmCreateReqVO;
import com.vhall.component.entity.export.vo.ExportAdmListReqVO;
import com.vhall.component.entity.export.vo.ExportAdmRspVO;
import com.vhall.component.entity.page.vo.PageVO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.support.PermissionSupport;
import com.vhall.component.plugin.common.support.Token;
import com.vhall.component.plugin.common.support.TokenThreadLocal;
import com.vhall.component.service.export.ExportService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 导出-admin平台控制器
 *
 * @author yuanzh
 */
@VhallComponent
public class ExportAdmController implements ExportAdmFacade {

    @Autowired
    private ExportService exportService;

    @Autowired
    private PermissionSupport support;

    @TokenAuth
    @Override
    public PageVO<ExportAdmRspVO> list(ExportAdmListReqVO reqVO) {
        final Token token = TokenThreadLocal.getToken();
        //0=全量导出列表数据（统计台） 1=房间列表导出 2=文档列表导出 3=问卷列表导出 4=用户列表导出 5=主持人列表导出 6=管理员列表导出 7=短视频列表
        String requiredPer = null;
        if (reqVO.getType() != null) {
            switch (reqVO.getType()) {
                case 0:
                    requiredPer = "sys:export:adm:list";
                    break;
                case 1:
                    requiredPer = "sys:room:list";
                    break;
                case 4:
                case 5:
                    requiredPer = "sys:account:list";
                    break;
                case 6:
                    requiredPer = "sys:admin:list";
                    break;
                default:
                    requiredPer = "";
            }
        }
//        if (StringUtils.isNotBlank(requiredPer) && support.lacksPermi(requiredPer, token)) {
//            throw new BusinessException(BizErrorCode.BIZ_NO_PERMISSION);
//        }
        return exportService.exportList(reqVO, token.getAccountId());
    }

    @TokenAuth
    @Override
    public JSONObject create(ExportAdmCreateReqVO reqVO) {
        final Token token = TokenThreadLocal.getToken();
        //0=全量导出列表数据（统计台） 1=房间列表导出 2=文档列表导出 3=问卷列表导出 4=用户列表导出 5=主持人列表导出 6=管理员列表导出
        String requiredPer = null;
        if (reqVO.getType() != null) {
            switch (reqVO.getType()) {
                case 0:
                    requiredPer = "sys:export:adm:list";
                    break;
                case 1:
                case 7:
                    requiredPer = "sys:room:export";
                    break;
                case 4:
                case 5:
                    requiredPer = "sys:account:export";
                    break;
                case 6:
                    requiredPer = "sys:admin:export";
                    break;
                default:
                    requiredPer = "";
            }
        }
//        if (StringUtils.isNotBlank(requiredPer) && support.lacksPermi(requiredPer, token)) {
//            throw new BusinessException(BizErrorCode.BIZ_NO_PERMISSION);
//        }
        exportService.createExport(reqVO, token.getAccountId());
        return new JSONObject();
    }

    @TokenAuth("sys:room:export")
    @Override
    public JSONObject reExport(AdmReExportReqVO reqVO) {
        exportService.reExport(reqVO);
        return new JSONObject();
    }
}
